﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SmallERP.PinBan.PB.View;
using SmallERP.PinBan.PB.Presenter;

namespace SmallERP.PinBan.PB.Froms
{
    public partial class FrmFullAutoPB : Form, IFullAutoPBView
    {
        private FullAutoPBPresenter _presenter;
        public FrmFullAutoPB()
        {
            InitializeComponent();
            SetHeaderTxt();

        }
        private void SetHeaderTxt()
        {
            string strHeadTxt = string.Empty;
            strHeadTxt ="全自动拼板-打印机:"+ DataTransfer.CurPrinerInfo.PName + "  模板名称:"+DataTransfer.curTemplateInfo.TemplateName + "    模板尺寸:("+DataTransfer.curTemplateInfo.Length +"X"+ DataTransfer.curTemplateInfo.Height+")英寸";
            this.Text = strHeadTxt;
        }


        private void btnOk_Click(object sender, EventArgs e)
        {
            if (btnOk.Text == "开始")
            {
                lblStatus.Text = "正在准备自动拼板...";
                _presenter.StartFAutoPB();
            }
            else if (btnOk.Text == "暂停")
            {
                _presenter.StopFAutoPB();
            }
        }

        #region IFullAutoPBView 成员

        public float CtmRaste
        {
            get { return Convert.ToInt32(txtWrate.Text.Trim()); }
        }

        public void CloseFrm()
        {
            throw new NotImplementedException();
        }
        delegate void UpCtrlDelete(string strResult, string strStatus);
        public void UpCtrl(string strResult, string strStatus)
        {
            if (lblStatus.InvokeRequired)
            {
                this.Invoke(new UpCtrlDelete(UpCtrl), new object[] { strResult, strStatus });
                return;
            }
            else
            {
                lblStatus.Text = strStatus;
                lblOverPB.Text = strResult;
            }
        }

        public void UpCtrlStatus(string strCurBStatus)
        {
            if (listBoxControl1.InvokeRequired)
            {
                this.Invoke(new UpString(UpCtrlStatus), new object[] { strCurBStatus });
                return;
            }
            listBoxControl1.Items.Insert(0, strCurBStatus + "-----------" + DateTime.Now.ToString());
        }

        public void UpCtrlClearBoxCount(string strCount)
        {
            if (lblClearBoxCount.InvokeRequired)
            {
                this.Invoke(new UpString(UpCtrlClearBoxCount), new object[] { strCount });
                return;
            }
            lblClearBoxCount.Text = strCount;
        }

        public void UpCtrlRemainPs(string strCount)
        {
            if (lblCount.InvokeRequired)
            {
                this.Invoke(new UpString(UpCtrlRemainPs), new object[] { strCount });
                return;
            }
            lblCount.Text = strCount;
        }
        delegate void UpString(string msg);
        delegate void UpBtn(string msg, bool btnEnable);
        public void SetBtn(string p, bool btnEnable)
        {
            if (btnOk.InvokeRequired)
            {
                this.Invoke(new UpBtn(SetBtn), new object[] { p, btnEnable });
                return;
            }
            btnOk.Text = p;
            btnOk.Enabled = btnEnable;
            if (p == "开始")
            {
                timer1.Enabled = false;
                progressBar1.Value = 0;
            }
            else if (p == "暂停")
            {
                timer1.Enabled = true;
            }
        }

        #endregion

        private void FrmFullAutoPB_Load(object sender, EventArgs e)
        {
            _presenter = new FullAutoPBPresenter(this);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            progressBar1.Value++;
            if (progressBar1.Value >= progressBar1.Maximum)
            {
                progressBar1.Value = 1;
            }
        }
    }
}
